/*
 * DesignDemoApp.java
 */
package nl.windesheim.archdemo;

import java.util.logging.Level;
import java.util.logging.Logger;
import nl.windesheim.archdemo.dao.AddressDao;
import nl.windesheim.archdemo.dao.CustomerDao;
import nl.windesheim.archdemo.dao.OrderDao;
import nl.windesheim.archdemo.dao.ProductDao;
import nl.windesheim.archdemo.model.Address;
import nl.windesheim.archdemo.model.Customer;
import nl.windesheim.archdemo.model.Order;
import nl.windesheim.archdemo.model.OrderLine;
import nl.windesheim.archdemo.model.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/** Inserts all Spring Beans with model classes into the database */
public class DbInsert {

    @Autowired
    private OrderDao orderDao;
    @Autowired
    private ProductDao productDao;
    @Autowired
    private CustomerDao customerDao;
    @Autowired
    private AddressDao addressDao;
    
    @Autowired
    private Address[] addresses;
    @Autowired
    private Customer[] customers;
    @Autowired
    private Product[] products;
    @Autowired
    private OrderLine[] orderLines;
    @Autowired
    private Order[] orders;

    public void run() {
        for(Address a: addresses){ addressDao.save(a); }
        for(Customer c: customers){customerDao.save(c); }
        for(Product p: products){productDao.save(p);}
        for(Order o: orders){
            orderDao.save(o);
        }

        
    }
    
    
    
    private final static Logger LOG = Logger.getLogger(DbInsert.class.getName());
    private static ApplicationContext context;

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
       
        try {
            context = new ClassPathXmlApplicationContext("data.xml");
            context.getBean(DbInsert.class).run();
        } catch (Exception ex) {
            LOG.log(Level.SEVERE, null, ex);
           
        }
         System.exit(0);
    }
}
